package com.typhoon.controller;

import com.typhoon.dao.User2Dao;
import com.typhoon.dao.User3Dao;
import com.typhoon.dao.User4Dao;
import com.typhoon.entity.User;
import com.typhoon.dao.UserDao;
import com.typhoon.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author shuya | dongfeng.zdf@alibaba-inc.com
 * @description
 * @date 2018/10/10 下午7:50
 * @description
 * @modified by
 * @since V2.0.0
 */
@RestController
@RequestMapping("/user")
public class IndexController {

    @Autowired
    private UserRepository userRepository;

    @Autowired
    private UserDao userDao;

    @Autowired
    private User2Dao user2Dao;

    @Autowired
    private User3Dao user3Dao;

    @Autowired
    private User4Dao user4Dao;

    @RequestMapping("/add")
    private User add(@RequestParam("name") String name,
                     @RequestParam("age") Integer age,
                     @RequestParam("sex") Integer sex) {
        User user = new User();
        user.setAge(age);
        user.setName(name);
        user.setSex(sex);
        user.setCreateTime(new Date());
        return this.userRepository.save(user);
    }

    @GetMapping("/jpa/list")
    private Object list() {
        return this.userRepository.findAll();
    }

    @GetMapping("/mybatis/list")
    private Object mybatis() {
        return this.userDao.findAll();
    }

    @GetMapping("/jdbctemplate/list")
    private Object jdbcTemplateList() {
        return this.user2Dao.findAll();
    }

    @GetMapping("/dbutils/list")
    private Object dbUtilsList() {
        return this.user3Dao.findAll();
    }

    @GetMapping("/jooq/list")
    private Object jooqList() {
        return this.user4Dao.findAll();
    }
}
